package cn.wolfcode.advice;

import cn.wolfcode.domain.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;

//全局异常处理器
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public Result ex(SQLIntegrityConstraintViolationException e){
        return Result.error("填入的数据异常");
    }
    @ExceptionHandler(DeptNameUniqueException.class)
    public Result ex(DeptNameUniqueException e){
        return Result.error(e.getMessage());
    }
    @ExceptionHandler(NoLoginException.class)
    public Result ex(NoLoginException e){
        return Result.error(e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public Result ex(Exception e){
        return Result.error("程序员失恋了,没人维护");
    }
}
